package com.deer.wms.system.manage.web;

import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.system.manage.model.CellLed;
import com.deer.wms.system.manage.service.CellLedService;
import com.deer.wms.system.manage.test.CellLedCriteria;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


@RestController
@RequestMapping("/cellLed")
public class CellLedController {
    @Autowired
    private CellLedService cellLedService;


    @PostMapping("/add")
    public Result add(@RequestBody CellLed cellLed) {
        cellLedService.add(cellLed);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody CellLed cellLed) {
        cellLedService.update(cellLed);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/list")
    public Result list(@RequestBody CellLedCriteria queryCriteria) {
        PageHelper.startPage(queryCriteria.getPageNum(), queryCriteria.getPageSize());
        List<CellLed> list = cellLedService.findList(queryCriteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @GetMapping("/delete")
    public Result delete(String ids) {
        cellLedService.delete(ids);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "卓品电子料架", notes = "")
    @PostMapping("/operate")
    public Result operate(@RequestBody CellLedCriteria cellLedBo, @ApiIgnore @User CurrentUser currentUser){
        cellLedService.ledControl(cellLedBo.getCellCodes(), cellLedBo.getColor(), cellLedBo.getTime(), cellLedBo.getLighttype());
        return ResultGenerator.genSuccessResult();
    }
}
